package com.byxy.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.byxy.entity.User;
import com.byxy.service.UserService;

public class UserLoginAction {

	private String name;
	private String pwd;
	@Resource
	private UserService userService;

	public String logout() {
		ServletActionContext.getRequest().getSession().removeAttribute("user");
		return "success";
	}

	public String doLogin() {
		System.out.println("name=" + name);
		System.out.println("pwd=" + pwd);
		User u = userService.findByLoginNameAndPassword(name, pwd);
		if (u == null) {
			ServletActionContext.getRequest().getSession().removeAttribute("user");
			return "xxx";
		} else {
			ServletActionContext.getRequest().getSession().setAttribute("user", u);
			return "success";
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

}
